<?php
class signupController extends Web_Controller_Base
{
    public function indexAction()
    {
        if(Web_Model_Member::isSignIn()){
            $this->forward('http://' . HOST . '/blog');
        }
        $this->setData('title', '注册');
        $this->setView('SignUp/index.tpl');
    }
    
    public function doAjaxAction()
    {
        if(Web_Model_Member::isSignIn()){
            exit;
        }
        $email    = $this->getPost('email', '');
        $nickname = $this->getPost('nickname', '');
        $password = $this->getPost('password', '');
        $repassword = $this->getPost('repassword', '');
        $ret['errCode']=0;
        $ret['errMsg'] ='success';
        try {
            Web_Model_Member::signUp($email, $nickname, $password, $repassword);
        }catch (Eren_DB_Exception $e){
            $ret['errCode'] = -10;
            $ret['errMsg']  = '系统异常，稍后重试';
        }catch (Exception $e){
            $ret['errCode'] = $e->getCode();
            $ret['errMsg']  = $e->getMessage();
        }
        echo json_encode($ret);
    }
}